<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
  </head>

  <body>
    <script>
      /*
            递归函数：
                在一个函数内部，自己调用自己 
            使用递归求 阶乘
                !n = n * (n-1) * (n-2) * ... * 2 * 1
                !(n-1) = (n-1) * (n-2) * ... * 2 * 1
                !(n-2) = (n-2) * ... * 2 * 1
                ...
                !2 = 2 * 1
                !1 = 1


                fn(n) {
                    if(n === 1)
                        return 1
                    else
                        return n * fn(n-1)
                }
        */

      function factorial(n) {
        return n == 1 ? 1 : n * factorial(n - 1)
      }

      let res = factorial(5)
      console.log(res);
    </script>
  </body>

</html>